/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package JFreeChartExtensions.chartsExporters.impl;

import JFreeChartExtensions.ExtendableChartPanel;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
 *
 * @author Nobody
 */
public class PNGChartExporter implements IChartExporter {

    @Override
    public void export(ExtendableChartPanel extendableChartPanel, File file, Dimension dimension) throws IOException {

        Dimension dim = extendableChartPanel.getSize();
        extendableChartPanel.setSize(dimension);
        BufferedImage bi = new BufferedImage(dimension.width,dimension.height, BufferedImage.TYPE_INT_ARGB);
        Graphics g = bi.createGraphics();
        extendableChartPanel.paint(g);
        g.dispose();
        ImageIO.write(bi, "png", file);
        extendableChartPanel.setSize(dim);
        extendableChartPanel.repaint();
    }
}
